package com.dm.library.http.callback;

import com.dm.library.http.base.JsonResult;
import com.google.gson.internal.$Gson$Types;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * 版 权: 深圳市迪蒙网络科技有限公司
 * 描 述:
 * 修 改 人: sushuo
 * 修改时间: 2016-12-20
 */
public abstract class RequestCallBack<T> {

    public Type mType;

    public RequestCallBack() {
        mType = getSuperclassTypeParameter(getClass());
    }

    static Type getSuperclassTypeParameter(Class<?> subclass) {
        Type superclass = subclass.getGenericSuperclass();
        if (superclass instanceof Class) {
            throw new IllegalArgumentException("Internal error: TypeReference constructed without actual type information");
        }
        ParameterizedType parameterized = (ParameterizedType) superclass;
        return $Gson$Types.canonicalize(parameterized.getActualTypeArguments()[0]);
    }

    public void onStart() {
    }

    public abstract void onSuccess(JsonResult<T> response);

    public abstract void onFailure(String msg);

    public abstract void onConnectFailure(String msg);

    /**
     * 用于gson解析
     *
     * @return
     */
    public Type getTokenType() {
        return null;
    }

}
